package com.exercise.poly_.polyarr_;

public class PolyArr {
    public static void main(String[] args) {
        person person[] = new person[5];
        person[0] = new person("jack",18);
        person[1] = new student("lihua",22,98.2);
        person[2] = new student("hubiao",22,424);
        person[3] = new teacher("wangfan",58,23000);
        person[4] = new teacher("zhoufang",26,26000);
        for (int i = 0;i<person.length;i++){
            System.out.println(person[i].say());
            //如果person[i]的运行类型为student
            if(person[i] instanceof student){
                //向下转型,也可以写成student student = (student) person[i];
                ((student)person[i]).study();
            }
            //如果person[i]的运行类型为teacher
            else if(person[i] instanceof teacher){
                ((teacher)person[i]).teach();
            }
        }

    }
}
